<!--
 * @Author: lc
 * @version: v1.2
 * @Date: 2021-10-25 11:37:57
 * @LastEditors: lc
 * @LastEditTime: 2021-10-27 11:16:11
 * @Descripttion: 
-->
<template>
  <div id="app">
    <!-- 数字：
    <div class="dome">
      <p v-pang-if="isShow">李超</p>
    </div>

    <span v-pang-show="show">{{num}}</span>
    <input v-focus />
    <button @click="handleClick">加分</button>
    <button @click="unbind">解绑</button>

    <dyt-table />-->
    <router-view />
  </div>
</template>

<script>
export default {
  name: 'App',
  directives: {
    pangShow: {
      // 指令的定义
      bind: function (el, bind, vnode) {
        if (bind.value) {
          el.style.display = 'block'
        } else {
          el.style.display = 'none'
        }

        console.log('el', el)
        console.log('bind', bind)
        console.log('vnode', vnode)
      },
      inserted: function (el) {
        el.focus()
        //绑定到节点
        console.log('2 - inserted')
      },
      update: function () {
        //组件更新
        console.log('3 - update')
      },
      componentUpdated: function () {
        //组件更新完成
        console.log('4 - componentUpdated')
      },
      unbind: function () {
        //解绑
        console.log('5 - unbind')
      }
    },
    focus: {
      inserted: function (el) {
        el.focus()
        //绑定到节点
        console.log('2 - inserted')
      }
    },
    pangIf: {
      bind: function (el, bind, vnode) {
        console.log('el', el)
        console.log('bind', bind)
        console.log('vnode', vnode)
        const dome = document.getElementsByClassName('dome')[0]
        console.log(dome)
        // console.log('app', dome.getElementsByTagName('p')[0])
        if (bind.value) {
          dome.removeChild(el)
        }
      }
    }
  },
  data() {
    return {
      num: 1,
      show: false,
      isShow: true
    }
  },
  mounted() {
    console.log(this.init()()) // jack

    var fn1 = this.fn()
    fn1() // 1 4
    fn1() // 1 5
  },
  methods: {
    // 解绑
    unbind() {
      this.$destroy()
    },
    handleClick() {
      this.num++
    },
    init() {
      var name = 'jack'
      return function () {
        return name
      }
    },

    // 闭包经典案例
    fn() {
      var num = 3
      return function () {
        var n = 0
        console.log(++n)
        console.log(++num)
      }
    }

    //
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
</style>
